// pages/recipe-edit/swipe/index.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    dataSource: {
      type: Array,
      value: []
    },
    materialList: {
      type: Array,
      value: []
    },
    show: {
      type: Boolean,
      value: false
    },
    _list: {
      type: Array,
      value: []
    },
    _alias: {
      type: Object,
      value: {}
    },
    _ingredientsList: {
      type: Array,
      value: []
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    current: 0
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onClose() {
      this.triggerEvent('close')
    },
    onChange(event) {
      this.setData({
        current: event.detail.current
      })
    },
    onPre() {
      const current = this.data.current;
      if (current > 0) {
        this.setData({
          current: current - 1
        })
      }else {
        wx.showToast({
          title: '没有更多了',
          icon: 'none'
        })
      }
    },
    onNext() {
      const current = this.data.current, dataSource = this.properties.dataSource;
      if (current < dataSource.length-1) {
        this.setData({
          current: current + 1
        })
      } else {
        wx.showToast({
          title: '没有更多了',
          icon: 'none'
        })
      }
    },
    onDelect(event){
      this.setData({
        current: 0
      })
      this.triggerEvent('delect', event.detail);
    },
    onAdd(event){
      this.triggerEvent('add', event.detail)
    },
    onRefresh(event){
      this.triggerEvent('refresh',event.detail)
    }
  }
})